// -----------------------------------------------------------------------
//  <copyright file="GetRoleByIdQuery.cs" company="LiuliuSoft">
//      Copyright (c) 2022-2024 DaprPlus. All rights reserved.
//  </copyright>
//  <site>https://dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2024/12/10 10:51:21</last-date>
// -----------------------------------------------------------------------

using DaprPlus.Identity.Domain.Entities;


namespace DaprPlus.Identity.Application.Identity.Roles.Queries;

[AuthConfig(typeof(Role), ResourceAccessType.RoleLimit, "GetById")]
public class GetRoleByIdQuery : SingleQuery<RoleOutDto?>
{
    public GetRoleByIdQuery(long id)
    {
        Check.GreaterThan(id, nameof(id), 0);
        Id = id;
    }

    public long Id { get; }
}

public class GetRoleByIdQueryHandler(IQueryRepository<Role> queryRepository)
    : IRequestHandler<GetRoleByIdQuery, RoleOutDto?>
{
    public async Task<RoleOutDto?> Handle(GetRoleByIdQuery request, CancellationToken cancellationToken)
    {
        var model = await queryRepository.FindAsync(request.Id, cancellationToken);
        return model?.MapTo<RoleOutDto?>();
    }
}

